package com.cn.kehong.controller;


import com.cn.kehong.api.IFactoryShiftService;
import com.cn.kehong.domain.FactoryShift;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/factoryShift")
public class FactoryShiftController {

    @Autowired
    private IFactoryShiftService factoryShiftService;

    @RequestMapping("/getFactoryShifts/{frontToken}")
    @ResponseBody
    public JsonResponse<List<FactoryShift>> getFactoryShifts(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<FactoryShift> > response = new JsonResponse<List<FactoryShift> >();
        List<FactoryShift> lists = factoryShiftService.getFactoryShifts(queryForm);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getFactoryShiftByName/{frontToken}")
    @ResponseBody
    public JsonResponse<FactoryShift> getFactoryShiftByName(String factoryName,String shiftType, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<FactoryShift> response = new JsonResponse<FactoryShift >();
        FactoryShift factoryShift = factoryShiftService.getFactoryShiftByName(factoryName,shiftType);
        response.setResult(factoryShift);
        response.setSuccess(null == factoryShift?false:true);
        return  response;
    }


    @RequestMapping("/addFactoryShift/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addFactoryShift(@RequestBody List<FactoryShift> factoryShifts, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = factoryShiftService.addFactoryShift(factoryShifts);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/updateFactoryShift/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateLaborRate(@RequestBody FactoryShift factoryShifts, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = factoryShiftService.updateFactoryShift(factoryShifts);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/deleteFactoryShiftById/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteFactoryShiftById(String id,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = factoryShiftService.deleteFactoryShiftById(id);
        return CommonUtil.getResponseData(response,result);
    }


    @RequestMapping("/getFactoryShiftsAll/{frontToken}")
    @ResponseBody
    public JsonResponse<List<FactoryShift>> getFactoryShiftsAll(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<FactoryShift> > response = new JsonResponse<List<FactoryShift> >();
        List<FactoryShift> lists = factoryShiftService.getFactoryShiftsAll(queryForm);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }
}
